// 关于首筑
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import '../../../tools/tools.dart';
import '../../webview/webview_page.dart';

class AboutPage extends StatefulWidget {
  const AboutPage({Key? key}) : super(key: key);

  @override
  State<AboutPage> createState() => _AboutPageState();
}

class _AboutPageState extends State<AboutPage> {
  List<Map<String, dynamic>> listOne = [
    {
      'title': '服务协议',
      'url': 'https://www.shouzhu.com.cn/shared/agreements',
      'text': ''
    },
    {
      'title': '隐私政策',
      'url': 'https://www.shouzhu.com.cn/shared/policy',
      'text': ''
    },
    {'title': '官方邮件', 'url': 'email', 'text': 'support@shouzhu.com.cn'},
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: SzColor.f4f4f4,
      appBar: buildAppBar(),
      body: Column(
        children: [
          SizedBox(
            height: rpx(310),
            width: getScreenWidth,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Image.asset(
                  'images/imgs/logo@2x.png',
                  width: rpx(130),
                  height: rpx(130),
                ),
                const Text('版本号')
              ],
            ),
          ),
          Column(
            children:
                listOne.map<Widget>((e) => buildItem(context, e)).toList(),
            // children: [Text('data')],
          ),
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text('Copyright2022-${DateTime.now().year}'),
                SizedBox(
                  height: rpx(10),
                ),
                const Text('shouzhu.com.cn 版权所有'),
              ],
            ),
          ),
        ],
      ),
    );
  }

  // 每项
  Widget buildItem(BuildContext context, Map<String, dynamic> one) {
    return Container(
      decoration: const BoxDecoration(
        color: Colors.white,
      ),
      child: InkWell(
        onTap: () {
          FPrint('e12');
          if (one['url'] == 'email') {
            //复制
            Clipboard.setData(ClipboardData(text: one['text']));
            // toast(context, title: '复制成功', icon: IconType.success);
            SzEasyLoading.showToast('复制成功');
          } else {
            // Get.toNamed(one['url']);
            Get.toNamed('webview', arguments: {
              WebConfig(url: one['url'], title: one['title']),
            });
          }
        },
        child: Container(
          margin: EdgeInsets.symmetric(horizontal: rpx(40)),
          padding: EdgeInsets.symmetric(vertical: rpx(30)),
          decoration: BoxDecoration(
            border: Border(
              bottom: BorderSide(
                width: rpx(2),
                color: SzColor.f4f4f4,
              ),
            ),
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(one['title']),
              Row(
                children: [
                  one['text'].length > 0
                      ? Padding(
                          padding: EdgeInsets.only(right: rpx(10)),
                          child: Text(one['text']))
                      : const SizedBox(),
                  Icon(
                    AliIcon.qingxuanzeyoujiantou,
                    color: const Color(0xffC8C8C8),
                    size: setSp(28),
                  )
                ],
              )
            ],
          ),
        ),
      ),
    );
  }

  AppBar buildAppBar() {
    return AppBar(
      title: const Text(
        '关于首筑',
        style: TextStyle(color: Colors.white),
      ),
      backgroundColor: SzColor.primary,
      centerTitle: true,
      leading: IconButton(
        onPressed: () {
          Get.back();
        },
        icon: Icon(
          Icons.chevron_left,
          color: Colors.white,
          size: setSp(60),
        ),
      ),
    );
  }
}
